package com.example.hms_boss.provider;

import com.example.hms_boss.MainAbility;
import com.example.hms_boss.ResourceTable;
import com.example.hms_boss.bean.CompanyInfo;
import com.example.hms_boss.bean.MessageInfo;
import ohos.agp.components.*;

import java.util.List;

public class MessaegsProvicer extends RecycleItemProvider {

    private List<MessageInfo.DataBean> list;
    private MainAbility slice;
    public MessaegsProvicer(List<MessageInfo.DataBean> list, MainAbility slice) {
        this.list = list;
        this.slice = slice;
    }


    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public Component getComponent(int i, Component component, ComponentContainer componentContainer) {
        if (component== null) {
            Component     cpt = LayoutScatter.getInstance(slice).parse(ResourceTable.Layout_message_listview_item,null,false);
            MessageInfo.DataBean  dataBean = list.get(i);
            Text nicknametext =(Text) cpt.findComponentById(ResourceTable.Id_message_nicknametext);
            Text companynametext =(Text) cpt.findComponentById(ResourceTable.Id_message_companynametext);
            Text msg_text =(Text) cpt.findComponentById(ResourceTable.Id_msg_text);
            nicknametext.setText(dataBean.getNickname());
             companynametext.setText(dataBean.getCompanyname()+"|"+dataBean.getJobname());
             msg_text.setText(dataBean.getMsg());
            return cpt;
        } else {
            return component;
        }
    }
}
